package com.wad.manager.controller;

import com.github.pagehelper.PageInfo;
import com.wad.entity.product.Brand;
import com.wad.manager.service.BrandService;
import com.wad.vo.common.Result;
import com.wad.vo.common.ResultCodeEnum;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wad
 * @date 2023/12/07 14:04
 * @project e-commerce
 **/

@RestController
@RequestMapping("/admin/product/brand")
public class BrandController {


    @Resource
    private BrandService brandService;

    @GetMapping("/list/{page}/{limit}")
    public Result list(@PathVariable("page") Integer page,@PathVariable("limit") Integer limit){

        PageInfo<Brand> pageInfo=brandService.findByPage(page,limit);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }


    @PostMapping("/save")
    public Result save(@RequestBody Brand brand){
        brandService.save(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }


    @PutMapping("/update")
    public Result update(@RequestBody Brand brand){
        brandService.update(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deletedById(@PathVariable("id") Long id){
        brandService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }


    @GetMapping("/findAll")
    public Result findAll(){
        List<Brand> brandList=brandService.findAll();
        return Result.build(brandList,ResultCodeEnum.SUCCESS);
    }
}
